/**
 * Coryright 2015-2020 www.eyaomall.cn
 * All rights reserved.
 * @author huwenqing
 * @date 2016年8月3日
 *
 */
package com.eyaomall.wxmanage.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eyaomall.wxmanage.common.helper.MemberHelper;
import com.eyaomall.wxmanage.dao.ArticleCategroyDao;
import com.eyaomall.wxmanage.dao.ArticleDao;
import com.eyaomall.wxmanage.dao.UserDao;
import com.eyaomall.wxmanage.model.po.Article;
import com.eyaomall.wxmanage.model.po.ArticleCategory;
import com.eyaomall.wxmanage.model.po.User;
import com.eyaomall.wxmanage.service.ArticleService;
import com.lycheeframework.core.cmp.kit.PageHTTPObject;

@Service
public class ArticleServiceImpl implements ArticleService {
	
	@Autowired
	private ArticleDao articleDao;
	
	@Autowired
	private UserDao userDao;
	
	@Autowired
	private ArticleCategroyDao articleCategroyDao;
	 
	/**
	 * 分页查询数据
	 */
	public Object pageDate(Article article, PageHTTPObject object) {
		return articleDao.page(article, object);
	}

	/**
	 * 保存编辑
	 */
	public int save(Article atricle) {
		User user = new User();
		user.setId(MemberHelper.getId());
		ArticleCategory ac = new ArticleCategory();
		ac.setName(atricle.getCategoryName());
		User  atr = (User) userDao.query(user);
		ArticleCategory atre =  (ArticleCategory) articleCategroyDao.queryById(ac);
		atricle.setUserId(atr.getId());
		atricle.setCategoryId(atre.getId());
		atricle.setClickNum(0);
		return (int) articleDao.insert(atricle);
	}

	/**
	 * 编辑页面获取数据
	 */
	public Object query(Article article) {
		return articleDao.query(article);
	}

	/**
	 * 编辑更新
	 */
	public int updateData(Article atrical) {
		return articleDao.update("updateEdit", atrical);
	}

	/**
	 * 根据ID删除文章库
	 * @param id
	 * @return
	 */
	public boolean del(Integer id){
		Article article = new Article();
		article.setId(id);
		article.setIsDeleted("y");
		
		return articleDao.update("deleteById",article) > 0 ? true : false;
	}
}
